package com.xspace.android.xafcommon.download;

import android.content.Context;

public class Download {

    public static Download download;
    private static DownloadManager mDownloadManager;

    public synchronized static Download getInstance() {
        if (download == null) download = new Download();
        if (mDownloadManager == null) mDownloadManager = new DownloadManager();
        return download;
    }

    public static void init(Context context, String serviceName, int maxsize, boolean reseedFlag) {
        DownConstants.taskMaxNumber = maxsize;
        DownConstants.reseedFlag = reseedFlag;
        FileUtils.initDownloadTempDir();
    }

    public void stop() {
    }

    public void downFile(LoadInfo req, IDownloadListener listener) {
        DownloadInfo info = new DownloadInfo(req);
        mDownloadManager.addTask(info.req.id + "", info, "", false, listener);
//	        try {
//        mDownloadServiceManager.downLoad(info, "" + req.id, req.directory, false, listener, null);
//			} catch (RemoteException e) {
//			}
//        public void addTask(String id, DownloadInfo downloads, String name,
//        boolean type, IDownCallback downCallback)

    }

    public void downImg(LoadInfo req, IDownloadImgListener listener) {
        DownloadInfo info = new DownloadInfo(req);
    }

    public void cancel(String id) {
        mDownloadManager.cancel(id);
    }

    public void pause(String id) {
        mDownloadManager.pause(id);
    }

    public void resume(String id) {
        mDownloadManager.resume(id);
    }

    public int getStatus(String id) {
        return mDownloadManager.getStatus(id);
    }

    public float getProgress(String id) {
        return mDownloadManager.getProgress(id);
    }

    public long getDowned(String id) {
        return mDownloadManager.getDowned(id);
    }

    public void resetCallback(String id, IDownloadListener listener, IDownloadImgListener imgListener) {
        mDownloadManager.setCallback(id, listener);
    }
}